package com.ruoyi.api.controller;

import com.ruoyi.api.service.VehicleService;
import com.ruoyi.api.vo.Vehicle;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆信息管理
 */
@RestController
@RequestMapping("/api/sys/vehicle")
public class VehicleController {

    @Autowired
    private VehicleService vehicleService;

    /**
     * 增加多个车辆状态信息
     * @param vehicle
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addVehice(@RequestBody  Vehicle[] vehicle){
        if(vehicle.length != 0){
            for (Vehicle vehicle1 : vehicle) {
                vehicleService.add(vehicle1);
            }
            return AjaxResult.success("添加成功");
        }else {
            return AjaxResult.error("添加失败");
        }

    }

    /**
     * 查询所有车辆信息
     * @return
     */
    @PostMapping("/selectAll")
    public AjaxResult selectAll(){
        List<Vehicle> list = vehicleService.selectAll();
        return AjaxResult.success(list);
    }

    /**
     * 修改车辆状态
     */
    @PostMapping("/update")
    public AjaxResult update(@RequestParam String value,
                             @RequestParam Integer state){
        vehicleService.update(value,state);
        return AjaxResult.success("修改成功");
    }

    @PostMapping("/delete")
    public AjaxResult delete(@RequestParam Long id){
        vehicleService.delectById(id);
        return AjaxResult.success("删除成功");
    }

}

